<template>
  <div class="login d-view">
    <div class="bg">
      <div class="mask">
      </div>
    </div>
    <div class="content">
      <div class="title">
        莹图大屏系统- V2.0
      </div>
      <div class="desc">
        请登录
      </div>
      <div class="row">
        <el-input v-model="account" placeholder="账号" prefix-icon="el-icon-user" clearable>
        </el-input>
      </div>
      <div class="row">
        <el-input v-model="password" placeholder="密码" show-password prefix-icon="el-icon-lock"></el-input>
      </div>
      <div class="row">
        <el-button type="primary" class="save-btn" @click="login()" :loading="loading">登 录</el-button>
      </div>
      <div class="row">
        <el-button class="save-btn" @click="close()">关 闭</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {baseRequest, SCREEN_CODE} from "@/utils/http/request";
import {closeWindow, initLogin, loginInfo} from "@/utils/brower";

export default {
  data() {
    return {
      account: '',
      password: '',
      loading: false
    }
  },
  mounted() {
    initLogin((userInfoStr) => {
      if (userInfoStr) {
        const userInfo = JSON.parse(userInfoStr)
        this.account = userInfo.login_name
        this.password = userInfo.login_password
      }
    })
  },
  methods: {
    close() {
      closeWindow()
    },
    getData() {
      this.loading = true
      baseRequest.screensaverGet().then(res => {
        if (res.code === '01') {
          this.$store.commit('SET_SCREENSAVER', res.is_show === '1')
          localStorage.setItem('screensaver', res.is_show)
          this.$router.replace('/choosePath')
        }
      }).catch(() => {
      }).finally(() => {
        this.loading = false
      })
    },
    login() {
      this.loading = true
      baseRequest.login({
        username: this.account,
        pwd: this.password,
        screenCode: SCREEN_CODE.construction
      }).then(res => {
        const {msg, code, token, screenName} = res
        if (code === '01') {
          loginInfo(this.account, this.password)
          this.$message.success(msg || '登录成功')
          sessionStorage.setItem('token', token)
          sessionStorage.setItem('screenName', screenName)
          sessionStorage.setItem('username', this.account)

          localStorage.setItem('username',this.account)
          localStorage.setItem('auto', window.btoa(this.password))
          this.getData()
          // this.$store.commit('SET_SCREENSAVER', true)
          // localStorage.setItem('screensaver', '0')
        }

      }).catch(() => {
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../../assets/style/base";

@keyframes move-mask {
  0% {
    margin-top: -4rem;
    margin-left: -4rem;
  }
  25% {
    margin-top: -4rem;
    margin-left: 4rem;
  }
  50% {
    margin-top: 4rem;
    margin-left: 4rem;
  }
  75% {
    margin-top: 4rem;
    margin-left: -4rem;
  }
  100% {
    margin-top: -4rem;
    margin-left: -4rem;
  }
}


.login {
  .bg {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;

    .mask {
      width: calc(100% + 18rem);
      height: calc(100% + 18rem);
      filter: blur(10rem);
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-image: linear-gradient(135deg, $color-alpha-info-90 20%, $color-alpha-info-64 50%, $color-alpha-info-8 80%);
      animation: move-mask ease-in infinite 5s;
      animation-direction: alternate;
      margin-top: -4rem;
      margin-left: -4rem;
    }
  }

  .content {
    width: 30rem;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    padding: $spacing-large;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    .title {
      font-size: 2rem;
      color: $color-black-1000;
      font-weight: bold;
    }

    .desc {
      font-size: 1.2rem;
      color: $color-black-700;
      margin-top: $spacing-small;
    }

    .row {
      margin-top: $spacing-base;

      button {
        width: 100%;

        span {

        }

      }
    }
  }
}
</style>
